# Bootstrap imputation

impute_via_bootstrap <- function(variable, data){
  new_variable <- data[,variable]
  to_impute <- is.na(new_variable)
  message(paste0("Imputed ",sum(to_impute)," missing values for ",variable))
  if(sum(to_impute) > 0) {
    new_variable[to_impute] <- 
      sample(x = new_variable[!to_impute],size = sum(to_impute),replace = TRUE)
  }
  
  return(new_variable)
}